package com.yunji.framework_template.books.web.controller;
import com.yunji.framework_template.books.orm.persistence.model.BooksUserRead;
import com.yunji.framework_template.books.biz.service.BooksUserReadService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yunji.framework_template.common.web.Result;
import com.yunji.framework_template.common.web.Page;

import java.util.List;

import org.apache.ibatis.annotations.Param;

/**
 *
 * Created by fenglibin on 2019/01/24.
 */
@Controller
@RequestMapping("/booksUserRead/")
public class BooksUserReadController {

    @Autowired
    BooksUserReadService booksUserReadService;

    @RequestMapping("selectAll")
    @ResponseBody
    public Result<List<BooksUserRead>> selectAll(){
        return Result.success(booksUserReadService.selectAll());
    }

    @RequestMapping("select")
    @ResponseBody
    public Result<BooksUserRead> selectByPrimaryKey(Integer id){
        return Result.success(booksUserReadService.selectByPrimaryKey(id));
    }

    @RequestMapping("selectByCondition")
    @ResponseBody
    public Result<List<BooksUserRead>> selectByCondition(BooksUserRead record){
        return Result.success(booksUserReadService.selectByCondition(record));
    }

    @RequestMapping("count")
    @ResponseBody
    public Result<Integer> count(BooksUserRead record){
        return Result.success(booksUserReadService.count(record));
    }

    @RequestMapping("insert")
    @ResponseBody
    public Result<Integer> insertSelective(BooksUserRead record){
        return Result.success(booksUserReadService.insertSelective(record));
    }

    @RequestMapping("update")
    @ResponseBody
    public Result<Integer> updateByPrimaryKeySelective(BooksUserRead record){
        return Result.success(booksUserReadService.updateByPrimaryKeySelective(record));
    }

    @RequestMapping("selectByPage")
    @ResponseBody
    public Result<Page<List<BooksUserRead>>> selectByPage(Page<BooksUserRead> page){
        List<BooksUserRead> list = null;
        page = page.sequentialDisplayCalculate(booksUserReadService.count(page.getObj()));
        if (page.getTotalCount() > 0) {
            list = booksUserReadService.selectByPage(page);
        }
        Page<List<BooksUserRead>> result = new Page<List<BooksUserRead>>(page, list);
        return Result.success(result);
    }

    @RequestMapping("deleteByCondition")
    @ResponseBody
    public Result<Integer> deleteByCondition(BooksUserRead record){
        return Result.success(booksUserReadService.deleteByCondition(record));
    }

    @RequestMapping("delete")
    @ResponseBody
    public Result<Integer> deleteByPrimaryKey(Integer id){
        return Result.success(booksUserReadService.deleteByPrimaryKey(id));
    }

}
